<?php
namespace Home\Controller;
use Think\Controller;
class HezuoController extends Controller {
    //头条精选
    public function toutiaoJXuser(){//用户信息
        $userId='05b6d281ad4c20c035cf5b5f97ab6a64';
        $gameId=3273;
        $merchantId=3273;
        $timestamp=time();
        $key='620D4A925E2E5B34';
        $strData="gameId={$gameId}@merchantId={$merchantId}@timestamp={$timestamp}@userId={$userId}@key={$key}";
        $sign=strtoupper(md5($strData));
        $strData=array(
            'gameId'=>$gameId,
            'merchantId'=>$merchantId,
            'timestamp'=>$timestamp,
            'userId'=>$userId,
            'sign'=>$sign
        );

        $url="https://game.deshangkeji.com/Api/Novel/Info";
        $ch = curl_init();
        curl_setopt($ch,CURLOPT_URL,$url); //设置请求地址
        curl_setopt($ch,CURLOPT_POST,true); //post请求
        curl_setopt($ch,CURLOPT_POSTFIELDS,$strData);// post请求的数据
        curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);//不需要证书验证
        curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);//不直接输出到页面
        $json = curl_exec($ch);
        $json=json_decode($json,true);
        dump($json);
    }
    public function toutiaoJXPay(){//金币扣取
        $price=cookie('price');

        $userId=cookie('uid');//61e2218932abdcf2cc903c7a3653e95b
        $gameId=3273;
        $merchantId=3273;
        $timestamp=time();
        $totalMoney=$price*20;
        $orderNum=cookie('orderid');
        $goodsName='知命测算';
        $key='620D4A925E2E5B34';
        $strData="gameId={$gameId}@goodsName={$goodsName}@merchantId={$merchantId}@orderNum={$orderNum}@timestamp={$timestamp}@totalMoney={$totalMoney}@userId={$userId}@key={$key}";
        $sign=strtoupper(md5($strData));
        $strData=array(
            'gameId'=>$gameId,
            'merchantId'=>$merchantId,
            'timestamp'=>$timestamp,
            'userId'=>$userId,
            'totalMoney'=>$totalMoney,
            'orderNum'=>$orderNum,
            'goodsName'=>$goodsName,
            'sign'=>$sign,
        );

        //容错重复支付
        $selectArr=S('sm_h5test|'.$orderNum);
        if($selectArr['status']==1){
            echo 1;
            exit;
        }

        $url="https://game.deshangkeji.com/Api/Novel/Recharge";
        $ch = curl_init();
        curl_setopt($ch,CURLOPT_URL,$url); //设置请求地址
        curl_setopt($ch,CURLOPT_POST,true); //post请求
        curl_setopt($ch,CURLOPT_POSTFIELDS,$strData);// post请求的数据
        curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);//不需要证书验证
        curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);//不直接输出到页面
        $json = curl_exec($ch);
        $jsonArr=json_decode($json,true);
        if($jsonArr['code']==200){//成功
            echo $json;
            $url="http://{$_SERVER['HTTP_HOST']}/zhiming/index.php/Home-Index-notify_urlwx?orderid={$orderNum}&trade_no={$jsonArr['data']}";
            $ch = curl_init();
            curl_setopt($ch,CURLOPT_URL,$url); //设置请求地址
            curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);//不需要证书验证
            curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);
            curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);//不直接输出到页面
            $json = curl_exec($ch);
        }else if($jsonArr['code']==202){//余额不足
        }else{
            echo 0;
        }
    }
}